/**
 * 收货地址相关API
 */
import {
	apiResquest
} from '@/utils/http.js'

import api from "@/config/api.js"; 


/**
 * 获取地区数据
 * @param id
 */
// export function getRegionsById(id = 0) {
// 	return http.request({
// 		url: `${api.common}/region/item/${id}`,
// 		method: Method.GET,
// 		message: false,
// 	});
// }
export const getRegionsById = (id) => {
	return apiResquest({
		url: 'app/laborer/item/' + id,
		method: 'get',
	})
}
/**
 * 获取收货地址列表
 * @returns {AxiosPromise}
 */
export function getAddressList() {
	return apiResquest({
		url: "app/address/list",
		method: "get",
	});
}


/**
 * 获取物流公司
 */
export function getLogistics() {
	return apiResquest({
		url: "/logistics",
		method: "get",
		needToken: true,
		params: {
			pageNumber: 1,
			pageSize: 200,
			disabled: "OPEN"
		},
	});
}

/**
 * 通过cityCode获取地区代码
 */
// export function getAddressCode(cityCode, townName) {
//   return apiResquest({
//     url: api.common + "/region/region",
//     method:"get",
//     needToken: true,
//     params: { cityCode, townName },
//   });
// }

/**
 * 添加收货地址
 * @param params 地址参数
 * @returns {AxiosPromise}
 */
export function addAddress(data) {
	return apiResquest({
		url: "app/address/add",
		method: "post",
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		data: data,
	});
}

/**
 * 编辑地址
 * @param id 地址ID
 * @param params 地址参数
 * @returns {AxiosPromise}
 */
export function editAddress(params) {
	return apiResquest({
		url: `app/address/update`,
		method: "post",
		header: {
			"content-type": "application/x-www-form-urlencoded"
		},
		data: params,
	});
}

/**
 * 删除收货地址
 * @param id
 */
export function deleteAddress(id) {
	return apiResquest({
		url: `app/address/delete/${id}`,
		method: "post",
		needToken: true,
	});
}



/**
 * 根据ID获取会员收件地址
 * @param id
 */
export function getAddressDetail(id) {
	return apiResquest({
		url: `app/address/${id}`,
		method: "get",
		loading: false,
		needToken: true,
	});
}

/**
 *
 */
export function getAddressDefault() {
	return apiResquest({
		url: `/memberAddress/get/default`,
		method: "get",
		loading: false,
		needToken: true,
	});
}
